home *** CD-ROM | disk | FTP | other *** search
- Path: canopus.cc.umanitoba.ca!mwcs!bryan.schwartz
- From: bryan.schwartz@mwcs.mb.ca (BRYAN SCHWARTZ)
- Newsgroups: comp.lang.c
- Subject: Function Pointers
- Message-ID: <8BC3202.028600318C.uuout@mwcs.mb.ca>
- Date: Wed, 06 Mar 96 08:34:00 -0600
- Distribution: world
- Organization: Muddy Waters Computer Society inc.
- Reply-To: bryan.schwartz@mwcs.mb.ca (BRYAN SCHWARTZ)
- X-Newsreader: PCBoard Version 15.22
- X-Mailer: PCBoard/UUOUT Version 1.20
-
- I'm having difficulty storing a finction address in a structure with my
- Borland Turbo3.0 for DOS compiler. The relevant code is as follows:
-
- unsigned far x_get( void far *SX); function prototype
- typedef union use this union to combine attributes + chars
- {
- unsigned ja; char + attrib.
- struct
- {
- char jb; char
- char jc; attrib.
- } jd;
- } UNI ;
- typedef UNI far *SX ; using far to access video memory
- typedef struct vid stuct to define screen
- {
- SX p; current position on screen
- ....code.....
- unsigned( far * s_get)(SX) ; function pointer in struct
- } STRU
-
- int main(void)
- {
- STRU *k ; near pointer to struct
- k->s_get = ( int near *)x_get ; PROBLEM here! ????
- return 0;
- }
- /* get a char + attribute from the screen using x_get() */
- unsigned far x_get( SX ptr )
- { /* SX ptr = address in screen buffer */
- return( ptr->ja );
- /* return char + attrib. to union */
- }
- Shoot holes in this code, Please! And tell me about it. I'm just
- starting learning C. How do I store a function's address in a structure
- successfully?
-